package z_map;

import java.awt.EventQueue;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.SwingConstants;

import java.awt.SystemColor;
import java.util.HashMap;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MapInput extends JInternalFrame {
	
	HashMap<String, MapData> map = new HashMap();
	
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private JLabel lblNewLabel_2;
	private JTextField userID;
	private JTextField irum;
	private JTextField phone;
	private JButton btnNewButton;
	private JLabel status;


	/**
	 * Create the frame.
	 */
	public MapInput(HashMap map) {
		super("Input",true, true, true, false);
		
		this.map = map;
		setBounds(100, 100, 331, 253);
		getContentPane().setLayout(null);
		getContentPane().add(getLblNewLabel());
		getContentPane().add(getLblNewLabel_1());
		getContentPane().add(getLblNewLabel_2());
		getContentPane().add(getUserID());
		getContentPane().add(getIrum());
		getContentPane().add(getPhone());
		getContentPane().add(getBtnNewButton());
		getContentPane().add(getStatus());

	}

	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("아이디");
			lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
			lblNewLabel.setBounds(12, 10, 57, 15);
		}
		return lblNewLabel;
	}
	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("성명");
			lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
			lblNewLabel_1.setBounds(12, 48, 57, 15);
		}
		return lblNewLabel_1;
	}
	private JLabel getLblNewLabel_2() {
		if (lblNewLabel_2 == null) {
			lblNewLabel_2 = new JLabel("연락처");
			lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
			lblNewLabel_2.setBounds(12, 89, 57, 15);
		}
		return lblNewLabel_2;
	}
	private JTextField getUserID() {
		if (userID == null) {
			userID = new JTextField();
			userID.setBounds(89, 7, 116, 21);
			userID.setColumns(10);
		}
		return userID;
	}
	private JTextField getIrum() {
		if (irum == null) {
			irum = new JTextField();
			irum.setBounds(89, 45, 116, 21);
			irum.setColumns(10);
		}
		return irum;
	}
	private JTextField getPhone() {
		if (phone == null) {
			phone = new JTextField();
			phone.setBounds(89, 86, 197, 21);
			phone.setColumns(10);
		}
		return phone;
	}
	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("입력");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					String id = userID.getText();
					String ir = irum.getText();
					String ph = phone.getText();
					
					if(id.equals("") || ir.equals("") || ph.equals("")){
						status.setText("항목이 비어 있습니다. 확인해 주세요");
					}else{
						MapData d = new MapData(id, ir, ph);
						map.put(id, d);
						status.setText("데이터가 저장되었습니다.");
					}
				}
			});
			btnNewButton.setBounds(89, 129, 129, 39);
		}
		return btnNewButton;
	}
	private JLabel getStatus() {
		if (status == null) {
			status = new JLabel("");
			status.setBackground(SystemColor.inactiveCaption);
			status.setOpaque(true);
			status.setBounds(12, 181, 285, 21);
		}
		return status;
	}
}
